package com.autorun.server.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.autorun.server.entity.Config;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 配置Mapper接口
 * 
 * @author autorun
 * @version 1.0.0
 */
@Mapper
public interface ConfigMapper extends BaseMapper<Config> {

    /**
     * 获取用户的所有配置
     * 
     * @param userId 用户ID
     * @return 配置列表
     */
    @Select("SELECT c.* FROM configs c " +
            "INNER JOIN user_configs uc ON c.id = uc.config_id " +
            "WHERE uc.user_id = #{userId} " +
            "ORDER BY c.create_time DESC")
    List<Config> findByUserId(@Param("userId") Integer userId);

    /**
     * 检查用户是否拥有配置
     * 
     * @param userId 用户ID
     * @param configId 配置ID
     * @return 数量
     */
    @Select("SELECT COUNT(*) FROM user_configs WHERE user_id = #{userId} AND config_id = #{configId}")
    Integer countUserConfig(@Param("userId") Integer userId, @Param("configId") Integer configId);
}